The introduction of eXtensible Markup Language (XML) and the EXtensibleStylesheet Language (XSL) specifications has provided an easy way to transform documents between various formats. This functionality has been included into Web development frameworks, giving them the ability to transform automatically an XML file into a document with different format such as HTML or XHTML, integrating the original data with graphic layout and user interface components. The XSL specifications are based on special constructs called templates that match a single element or a set of similar elements and rewrite them and their content based on instructions defined in the template.
Unfortunately, a problem arises when the structure of the XML document to process is not well defined. For example, the same element can be used for different purposes inside the XML document and based on these purposes multiple different transformations must be implemented. The problems get even worse when the task involves transforming HTML documents. For example the link element “a” can appear over a thousand times in different sections of a web page, such as in the main navigation bar, in hidden menus, to make images clickable, and as a button to execute JavaScript functions. Writing XSL templates that modify all these elements can increase complexity in an unpredictable way.
An illustrative example of these difficulties with a simple XSL file managing HTML links (“a” elements) is shown in FIG. 1. As illustrated, the XSL file:                (1) changes the “href” attribute using an XPath extension function called myext:normalize-url( );        (2) if the link contains “target” attribute with value “_blank”, remove it and set “class” attribute to “external” value, otherwise “class” attribute will get value “internal”;        (3) if the “a” content is an image (“img” element), then set new content to image “alt” attribute otherwise apply templates to its children; and        (4) use the “identity” template (last one) to simply copy elements as they are if they are not “a” elements.        
Accordingly, as shown the same instructions have to be written at least twice to keep templates simple and to cover all the combinations of the above transformations. More powerful XSL constructs like name templates or xsl:choose or xsl:if could be utilized and the resulting XSL document will be more optimized, but also will be more complex and less readable.